<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:head>
        <title>#{bundle.bv}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
            <h:form prependId="false" >
               <script type="text/javascript">  
                   var doInitForm=false;
                   function setDoInitForm(st) {doInitForm=st;}
                   
                   function handleCompleteSaving(xhr, status, args) {  
                        if(args.validationFailed || !args.success) {
                            
                        }else 
                            setTimeout(function() {
                                if (doInitForm==true) btnBV.jq.click();  
                            }, 3000);
                    }
                    
                    function customRK(e, id) {
                      var code = (e.keyCode ? e.keyCode : e.which);
                       if(code==13) {
                            if (id=="bvCIF") {
                               rcbvGetCustomer();
                            }
                            e.preventDefault ? e.preventDefault() : e.returnValue = false;
                            e.stopPropagation();
                       }
                    }
                    
                </script>  
               
                <p:outputPanel autoUpdate="true">
                <p:toolbar>
                    <p:toolbarGroup align="left">
                        <p:commandButton value="#{bundle.btnNew}" icon="ui-icon-document"
                                         widgetVar="btnBV" oncomplete="setDoInitForm(false);"
                                         rendered="#{menuBean.cekButtonAccess(401,'INS;')}"
                                         action="#{bvBean.newData()}" update="displayBV" process="@this">
                            <pe:resetEditableValues for="displayBV"/>  
                        </p:commandButton>  
                        
                        <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk"
                                         action="#{bvBean.trySave()}" disabled="#{!bvBean.editMode}"
                                         rendered="#{menuBean.cekButtonAccess(401,'INS;')}"
                                         oncomplete="setDoInitForm(true); handleCompleteSaving(xhr, status, args);" 
                                         update="displayBV" >
                        </p:commandButton> 
                    </p:toolbarGroup>
                    
                    <p:toolbarGroup align="right">
                        <p:commandButton id="doNothingBV" type="button" value="" style="width: 0px; height: 0px;"/> 
                         <p:defaultCommand target="doNothingBV"/> 
                    </p:toolbarGroup>
                </p:toolbar>
                </p:outputPanel>  

                <h:panelGrid id="displayBV" styleClass="addELIT" cellpadding="0" border="0" >
                    <h:panelGrid columns="1" rowClasses="panelGridId" >
                        <p:panel header="#{bundle.bv}">
                            <h:panelGrid columns="3" border="0" cellpadding="0" cellspacing="5">
                                <h:outputLabel value= "#{bundle.date}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{bvBean.bv.bvDate}" />
                                
                                <h:outputLabel value= "#{bundle.bvNo}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{bvBean.bv.bvNo}" />
                                
                                <h:outputLabel value= "#{bundle.bvtype}" /><h:outputLabel value= ":" />
                                <h:panelGrid columns="2" cellpadding="0" cellspacing="0" >
                                    <p:selectOneMenu value="#{bvBean.bv.bvType}" id="bvBvtype" label="#{bundle.bvtype}" 
                                            requiredMessage="#{bundle.bvType} #{bundle.requiredInput}" 
                                            required="true" style="width: 150px;" disabled="#{!bvBean.editMode}">
                                        <f:selectItem itemLabel="" itemValue="" />
                                        <f:selectItems value="#{bvBean.availableType}" />
                                        <p:ajax update="msgbvBvtype" />  
                                    </p:selectOneMenu>
                                    <p:message id="msgbvBvtype" for="bvBvtype" display="icon" />
                                </h:panelGrid>
                                
                                <h:outputLabel value= "#{bundle.bank}" /><h:outputLabel value= ":" />
                                <h:panelGrid columns="2" cellpadding="0" cellspacing="0" >
                                    <p:selectOneMenu value="#{bvBean.bv.bankId}" id="bvBank" label="#{bundle.bank}" 
                                            requiredMessage="#{bundle.bank} #{bundle.requiredInput}" 
                                            required="true" style="width: 150px;" disabled="#{!bvBean.editMode}">
                                        <f:selectItem itemLabel="" itemValue="" />
                                        <f:selectItems value="#{bvBean.availableBank}" />
                                        <p:ajax update="msgbvBank" />  
                                    </p:selectOneMenu>
                                    <p:message id="msgbvBank" for="bvBank" display="icon" />
                                </h:panelGrid>
                                
                                <h:outputLabel value= "#{bundle.currency}" /><h:outputLabel value= ":" />
                                <h:panelGrid columns="2" cellpadding="0" cellspacing="0" >
                                    <p:selectOneMenu value="#{bvBean.bv.currencyId}" id="bvCurrency" label="#{bundle.currency}" 
                                            requiredMessage="#{bundle.currency} #{bundle.requiredInput}" 
                                            required="true" style="width: 150px;" disabled="#{!bvBean.editMode}">
                                        <f:selectItem itemLabel="" itemValue="" />
                                        <f:selectItems value="#{bvBean.availableCurrency}" />
                                        <p:ajax update="msgbvCurrency" />  
                                    </p:selectOneMenu>
                                    <p:message id="msgbvCurrency" for="bvCurrency" display="icon" />
                                </h:panelGrid>
                                                                
                                <h:outputLabel value= "#{bundle.description}" /><h:outputLabel value= ":" />
                                <p:inputTextarea autoResize="false" rendered="true" rows="1" cols="50" 
                                                 value="#{bvBean.bv.description}" disabled="#{!bvBean.editMode}"/>
                            </h:panelGrid>
                            
                            
                            <p:panel>
                            <pe:masterDetail id="bvMD" selectLevelListener="#{selectLevelListener.handleNavigation}" style="width: 470px;">
                                <pe:masterDetailLevel level="1" levelLabel="#{bundle.bvdet}">
                                    <p:outputPanel autoUpdate="true">
                                        <p:dataTable id="dtBvdetails" var="bvdet" value="#{bvBean.bv.bvdets}" rowIndexVar="noUrut2" >
                                            <p:column style="width: 11px;">
                                                <f:facet name="header">No</f:facet>
                                                    <h:outputText value="#{noUrut2+1}" styleClass="numPos" >
                                                        <f:convertNumber groupingUsed="true"/>
                                                    </h:outputText>
                                            </p:column>
                                            
                                            <p:column style="width: 100px;">
                                                <f:facet name="header">#{bundle.bvaccnt}</f:facet>
                                                <h:outputText value="#{bvBean.getBvaccntName(bvdet.bvaccntId)}" style="width:100px;" />
                                            </p:column>
                                            
                                            <p:column style="width: 80px;">
                                                <f:facet name="header">#{bundle.amount}</f:facet>
                                                <h:outputText value="#{bvdet.amount}" styleClass="numPos" >
                                                    <f:convertNumber groupingUsed="true"/>
                                                </h:outputText>
                                            </p:column>

                                            <p:column style="width:auto">
                                                <f:facet name="header">#{bundle.description}</f:facet>
                                                <h:outputText value="#{bvdet.description}"  />
                                            </p:column>

                                            <p:column style="width:70px">
                                                <f:facet name="header">Actions</f:facet>
                                                    <p:commandLink value="Add" actionListener="#{bvBean.newDetail()}" disabled="#{!bvBean.editMode}">
                                                    <pe:selectDetailLevel contextValue="#{null}" preserveInputs="true"/>
                                                </p:commandLink><p:spacer width="3"/>

                                                <p:commandLink value="Edit" actionListener="#{bvBean.editDetail(bvdet)}" disabled="#{!bvBean.editMode or bvdet.bvaccntId==null}">
                                                    <pe:selectDetailLevel contextValue="#{bvdet}" preserveInputs="true"/>
                                                </p:commandLink><p:spacer width="3"/>

                                                <p:commandLink value="Del" actionListener="#{bvBean.handleRemoveDetail}" disabled="#{!bvBean.editMode or bvdet.bvaccntId==null}">
                                                    <p:collector value="#{bvdet}" removeFrom="#{bvBean.bv.bvdets}" />  
                                                </p:commandLink>
                                            </p:column>
                                        </p:dataTable>
                                    </p:outputPanel>
                                </pe:masterDetailLevel>
                                
                                
                                <pe:masterDetailLevel level="2" levelLabel="Add/edit" contextVar="bvdet" >
                                    <h:panelGrid id="frmBV" columns="3" border="0" cellpadding="0" cellspacing="10" >
                                        <h:outputLabel value= "#{bundle.bvaccnt}" /><h:outputLabel value=":"/>
                                        <p:selectOneMenu value="#{bvBean.bvaccntId}" style="width: 170px;" >
                                            <f:selectItems value="#{bvBean.availableBvaccnt}" />
                                        </p:selectOneMenu>
                                        
                                        <h:outputLabel value= "#{bundle.amount}" /><h:outputLabel value=":"/>
                                        <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                                            <pe:inputNumber decimalSeparator="." thousandSeparator="," maxValue="99999999999999999999.99" minValue="0" 
                                                styleClass="money" value="#{bvBean.unsaveDetail.amount}" style="width: 150px;"
                                                         id="bvdetAmount" required="true" label="#{bundle.amount}"
                                                requiredMessage="#{bundle.amount} #{bundle.requiredInput}">
                                                <p:ajax update="msgbvdetAmount" process="@this" /> 
                                            </pe:inputNumber>
                                            <p:message id="msgbvdetAmount" for="bvdetAmount" display="icon" />
                                        </h:panelGrid>
                                        
                                        <h:outputLabel value= "#{bundle.description}" /><h:outputLabel value=":"/>
                                        <p:inputTextarea autoResize="false" rows="1" cols="40" value="#{bvBean.unsaveDetail.description}" />
                                        
                                    </h:panelGrid>
                                    
                                    <h:panelGrid cellpadding="0" >
                                        <f:facet name="footer">  
                                            <p:commandButton value="Back" icon="ui-icon ui-icon-arrowthick-1-w" process="@this">
                                                <pe:resetEditableValues for="frmBV"/>  
                                                <pe:selectDetailLevel step="-1"/>
                                            </p:commandButton>
                                            
                                            <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk" actionListener="#{bvBean.saveDetail()}"/>
                                            
                                            <p:commandButton value="#{bundle.btnNew}" icon="ui-icon-document" actionListener="#{bvBean.newDetail()}" 
                                                             process="@this" update="frmBV">
                                                <pe:resetEditableValues for="frmBV"/>  
                                            </p:commandButton>  
                                            
                                        </f:facet>
                                    </h:panelGrid>
                                    
                                </pe:masterDetailLevel>
                            </pe:masterDetail>
                            </p:panel>
                             
                        </p:panel>
                    </h:panelGrid>    
                </h:panelGrid>
            </h:form>
        </ui:composition>
    </h:body>
</html>